package com.bingxue.edu.framework.security;

import cn.dev33.satoken.annotation.handler.SaAnnotationHandlerInterface;
import com.bingxue.edu.management.auth.EmployeeAuthUtil;
import org.springframework.stereotype.Component;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/**
 * 自定义注解 ApiResource 处理器
 * @author panbo
 * @since 2024/8/29
 */
@Component
public class ApiResourceCheckHandler implements SaAnnotationHandlerInterface<ApiResource> {

    @Override
    public Class<ApiResource> getHandlerAnnotationClass() {
        return ApiResource.class;
    }

    @Override
    public void check(Annotation at, Method method) {
        SaAnnotationHandlerInterface.super.check(at, method);
    }

    @Override
    public void checkMethod(ApiResource apiResource, Method method) {
        String resourceCode = apiResource.value();
        EmployeeAuthUtil.STP.checkPermission(resourceCode);
    }
}
